package com.dzsw.utils;

import com.dzsw.mybatisx.gen.util.GenConf;
import com.dzsw.showdoc.bean.ShowDocConf;
import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;

public class YamlUtil {

    private static final Yaml yaml = new Yaml();

    public static GenConf readGenConfYaml(String yamlName) throws Exception {
        return readYaml(yamlName, GenConf.class);
    }

    public static <T> T readYaml(String yamlName, Class<T> clazz) throws Exception {
        String fileName = ClassLoader.getSystemResource(yamlName).getPath();
        return yaml.loadAs(new FileInputStream(fileName), clazz);
    }

    public static void main(String[] args) throws Exception {
//        Yaml yaml = new Yaml();
//        String fileName = ClassLoader.getSystemResource("application.yml").getPath();
//        GenConf genConf = yaml.loadAs(new FileInputStream(fileName), GenConf.class);
//        System.out.println(genConf.getAuthor());
//        ShowDocConf conf = new ShowDocConf();
//        conf.setCatId(1);
//        conf.setGetPagesBycatUrl("111");
//        conf.setPageInfoUrl("222");
//        conf.setCookieValue("333");
//        conf.setItemId(0);
//        conf.setCatId(0);
//        conf.setSavePath("444");
//        Yaml y = new Yaml();
//        String ss = y.dump(conf);
//        System.out.println(ss);
//        Object obj = y.load(ss);
//        String s = "{name: '222', id: 11}";

//        System.out.println(Integer.BYTES);
//        System.out.println(Integer.toHexString(1));
//        System.out.println(JsonUtil.toJson(System.getenv()));
        Yaml yaml = new Yaml();
        String fileName = "d:\\tmp\\test.yml";
        Map<String, Object> map = yaml.loadAs(new FileInputStream(fileName), Map.class);
        System.out.println(JsonUtil.toJson(map));
    }
}
